import 'package:flutter/material.dart';
import 'package:my_flutter_tool/util/app_util.dart';

///对话框背景与拦截
class DialogBg extends StatelessWidget {
  const DialogBg({
    Key key,
    this.child,
    this.allowBack = true,
    this.bottom = false,
  }) : super(key: key);

  ///子控件
  final Widget child;

  ///允许返回
  final bool allowBack;

  ///显示在底部
  final bool bottom;

  ///返回拦截
  Future<bool> _onWillPop(BuildContext context) async {
    return await Future.value(allowBack);
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      child: Column(
        mainAxisAlignment:
            bottom ? MainAxisAlignment.end : MainAxisAlignment.center,
        children: [
          Material(
            color: Colors.transparent,
            elevation: 0,
            child: child,
          ),
          if (bottom) SizedBox(height: 40.w),
        ],
      ),
      onWillPop: () async => await _onWillPop(context),
    );
  }
}
